
clear 
use "$path\Intermediary Data\p_minus_pstar\petoile_0_200_psychologicalprices_logregression.dta"

forvalues i=400 (200) 3200 {
local j=`i'-200
append using "$path\Intermediary Data\p_minus_pstar\petoile_`j'_`i'_psychologicalprices_logregression.dta"

}




******** V-shaped graph *****

bysort id (daten) : gen pht_moins_petoile_temp=log_prix_ht[_n-1] - log_petoile
bysort id: egen mean_tc_moins_petoile=mean(pht_moins_petoile_temp)
gen pht_moins_petoile=pht_moins_petoile_temp-mean_tc_moins_petoile
replace pht_moins_petoile=pht_moins_petoile*100


bysort id (daten): gen forward_change=(prix[_n]-prix[_n-1]!=0)
bysort id (daten): gen positive_change=(prix[_n]-prix[_n-1]>0)
bysort id (daten): gen negative_change=(prix[_n]-prix[_n-1]<0)

capture drop log_price*
bysort id (daten): gen log_priceht_change=log_prix_ht[_n]-log_prix_ht[_n-1]
bysort id (daten): gen log_price_change=log(prix[_n])-log(prix[_n-1])
replace log_priceht_change=. if log_price_change==0
replace log_priceht_change=log_priceht_change*100

gen pos_log_priceht_change=log_priceht_change
replace pos_log_priceht_change=. if pos_log_priceht_change<0

gen neg_log_priceht_change=log_priceht_change
replace neg_log_priceht_change=. if neg_log_priceht_change>0

xtile xt_pht_moins_petoile=pht_moins_petoile if abs(pht_moins_petoile)<12, nq(100)
bysort  xt_pht_moins_petoile: gen first_obs_quantile=1 if _n==1
bysort  xt_pht_moins_petoile: egen mean_forward_change=mean(forward_change)
bysort  xt_pht_moins_petoile: egen mean_positive_change=mean(positive_change)
bysort  xt_pht_moins_petoile: egen mean_negative_change=mean(negative_change)
bysort  xt_pht_moins_petoile: egen mean_pht_moins_petoile=mean(pht_moins_petoile)




graph twoway (histogram pht_moins_petoile if abs(pht_moins_petoile)<12, density yaxis(1) col(gs10%50) yscale(range(0(0.025)0.125) axis(1)) ylabel(0(0.025)0.125,axis(1))) ///
(scatter mean_positive_change mean_pht_moins_petoile if first_obs_quantile==1 & xt_pht_moins_petoile!=., col(gs8) yaxis(2) yscale(range(0(0.10)0.5) axis(2)) ylabel(0(0.10)0.5,axis(2)))  ///
(scatter mean_negative_change mean_pht_moins_petoile if first_obs_quantile==1 & xt_pht_moins_petoile!=., col(black)  ///
yaxis(2) yscale(range(0(0.10)0.5) axis(2)) ylabel(0(0.10)0.5,axis(2)) graphregion(color(white)) ///
legend(offp) xtitle("p-p* (in %)") ytitle("Probability of price changes", axis(2)) ytitle("Density", axis(1)))
graph export "$path\Graphs_Tables\Figure3.png", replace
graph export "$path\Graphs_Tables\Figure3.eps", replace




* Closing the gap

bysort  xt_pht_moins_petoile: egen mean_pos_log_priceht_change=mean(pos_log_priceht_change)
bysort  xt_pht_moins_petoile: egen mean_neg_log_priceht_change=mean(neg_log_priceht_change)
bysort  xt_pht_moins_petoile: egen mean_nonzero_log_priceht_change=mean(log_priceht_change)

replace mean_neg_log_priceht_change=-mean_neg_log_priceht_change

graph twoway (scatter mean_nonzero_log_priceht_change mean_pht_moins_petoile if first_obs_quantile==1 & xt_pht_moins_petoile!=., col(black)  graphregion(color(white)) ///
legend(order(1 "Non-zero price changes") cols(1)) xtitle("p-p* (in %)") ytitle("Non-zero price variations (in %)"))
graph export "$path\Graphs_Tables\FigureA4a.png", replace
graph export "$path\Graphs_Tables\FigureA4a.eps", replace


graph twoway (scatter mean_neg_log_priceht_change mean_pht_moins_petoile if first_obs_quantile==1 & xt_pht_moins_petoile!=., col(gs10)  graphregion(color(white))) ///
(scatter mean_pos_log_priceht_change mean_pht_moins_petoile if first_obs_quantile==1 & xt_pht_moins_petoile!=., col(black)  graphregion(color(white)) ///
legend(order(1 "Minus negative price changes" 2 "Positive price changes") cols(1)) xtitle("p-p* (in %)") ytitle("Non-zero price variations (in %)"))
graph export "$path\Graphs_Tables\FigureA4b.png", replace
graph export "$path\Graphs_Tables\FigureA4b.eps", replace



